<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>x小区管理</title>
    <meta name="decorator" content="default"/>
    <script>
        var isok=1;
        $(function(){
            $("#cname").blur(function(){
                var oldCommName=$("#oname").val();
                var commName=$("#cname").val();
                var aes=$("#areaId").val();
                if(aes=="请选择"){
                    var tt=document.getElementById("tt");
                    tt.innerHTML="请选择区域名称";
                }else{
                    $.ajax({
                        type : "POST",
                        url : "${ctx}/sys/community/agentCheckCommName",
                        data : {
                            oldCommName : oldCommName,
                            commName:commName,
                            aes:aes
                        },
                        success : function(data) {
                            if(data=="false"){
                                document.getElementById("nn").innerHTML="该小区名称已经存在！";
                                isok=2;
                            }else{
                                document.getElementById("nn").innerHTML="*";
                                isok=1;
                            }
                        }
                    });
                }

            });
        });

    </script>
    <script type="text/javascript">

        $(document).ready(function() {
            $("#box").focus();
            $("#inputForm").validate({
                rules:{
                 //   commName: {remote: "${ctx}/sys/community/checkCommName?oldCommName=" + encodeURIComponent('${tbCommunity.commName}')},
                    areaId:{
                        required:true,
                        areaId:"areaId"
                    }
                },
             /*  messages: {
                    commName: {remote: "该小区名称已存在"}
                },*/
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            $.validator.addMethod("areaId",function(values,elements){
                if(values=="请选择"){
                    var tt=document.getElementById("tt");
                    tt.innerHTML="请选择区域名称";
                    return false;
                }else if(isok==2){
                    document.getElementById("nn").innerHTML="该小区名称已经存在！";
                    return false;
                }else{
                    var tt=document.getElementById("tt");
                    tt.innerHTML="*";
                    return true;
                }
            },"");
            $("#areaId").change(function(){
                var tt=document.getElementById("tt");
                tt.innerHTML="*";
            });
        });
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/sys/community/listCommunity">小区列表</a></li>
    <li class="active"><a href="${ctx}/sys/community/form?id=${tbCommunity.id}">小区${not empty tbCommunity.id?'修改':'添加'}</a></li>
</ul><br/>
<form:form id="inputForm" modelAttribute="tbCommunity" action="${ctx}/sys/community/communityEdit" method="post" class="form-horizontal">
    <form:hidden path="id"/>
    <sys:message content="${message}"/>
    <div class="control-group">
        <label class="control-label">省:</label>
        <div class="controls">
            <form:input path="provinceName" htmlEscape="false" maxlength="50" class="required" readonly="true"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">市:</label>
        <div class="controls">
            <form:input path="cityName" htmlEscape="false" maxlength="50" class="required" readonly="true"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">区域名称:</label>
        <div class="controls">
            <span>
						<select id="areaId" name="areaId" class="input-medium">
							<option>请选择</option>
							<c:forEach items="${areasList}" var="areas">
                                <c:choose>
                                    <c:when test="${tbCommunity.areaId eq areas.areaid}">
                                        <option  value="${areas.areaid}" selected >${areas.area}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option  value="${areas.areaid}" >${areas.area}</option>
                                    </c:otherwise>
                                </c:choose>

                            </c:forEach>
						</select>
            </span>
            &nbsp;&nbsp;
           <%-- <span>
						<select id="box1" name='citys' class="input-medium">
                            <option >请选择</option>
                            <input type="hidden" id="cityId" name="cityId" />
                            <input type="hidden" id="cityName" name="cityName"/>
						</select>

					</span>--%>
            &nbsp;&nbsp;
          <%--  <span>
					<select id="box2" name='areas' class="input-medium required">
                        <option>请选择</option>
                        <input type="hidden" id="areaId" name="areaId" />
                        <input type="hidden" id="areaName" name="areaName"/>
					</select>
					</span>--%>
            <span class="help-inline"><font color="red" id="tt">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">小区名称:</label>
        <div class="controls">
           <input id="oname" name="oldCommName" type="hidden" value="${tbCommunity.commName}">
            <form:input path="commName" htmlEscape="false" maxlength="50"  class="required" id="cname"/>
            <span class="help-inline"><font color="red" id="nn">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">详细地址:</label>
        <div class="controls">
            <form:input path="address" htmlEscape="false" maxlength="50" class="required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label">是否显示:</label>
        <div class="controls">
            <form:radiobuttons path="isActive" items="${fns:getDictList('show_hide')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required"/>
            <span class="help-inline">该小区是否显示到微信中</span>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>

    <div class="form-actions">
       <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</form:form>
</body>
</html>